package com.shiliao.framework.ui.widght;

import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shiliao.framework.R;

/**
 * Created by yjl on 2017/7/24.
 */

public class FooterView extends RelativeLayout {
    private Context context;
    private View mRootView;
    private LinearLayout loadingView;
    private TextView noMoreData;
    private Handler handler = new Handler();

    public FooterView(Context context) {
        super(context);
        initFooterView(context);
    }

    public FooterView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initFooterView(context);
    }

    public FooterView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initFooterView(context);
    }

    private void initFooterView(Context context) {
        this.context = context;
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mRootView = inflater.inflate(R.layout.layout_footer_view, this);
        loadingView = (LinearLayout) mRootView.findViewById(R.id.view_loading);
        noMoreData = (TextView) mRootView.findViewById(R.id.footer_no_more_data);
        noMoreData.setVisibility(View.GONE);
    }

    /**
     * 显示加载中
     */
    public void showLoading() {
        if (loadingView != null) {
            loadingView.setVisibility(View.VISIBLE);
        }
        if (noMoreData != null) {
            noMoreData.setVisibility(GONE);
        }
    }

    /**
     * 加载完毕
     */
    public void showLoadFinish() {
        if (loadingView != null) {
            loadingView.setVisibility(View.GONE);
        }
        if (noMoreData != null && context != null) {
            noMoreData.setVisibility(VISIBLE);
            noMoreData.setText(context.getText(R.string.footer_load_finish));
        }
    }

    /**
     * 暂无更多数据
     */
    public void showNomoreData() {
        if (loadingView != null) {
            loadingView.setVisibility(View.GONE);
        }
        if (noMoreData != null && context != null) {
            noMoreData.setVisibility(VISIBLE);
            noMoreData.setText(context.getText(R.string.footer_no_more_data));
        }
    }
}
